Vue.prototype.$hasPermission = (code) =>{
  let codeList = store.state.auth.control_list
  if(codeList.includes(code)){
    return true
  }else{
    return false
  }
}
// 路由守卫，实现权限验证。拦截
router.beforeEach((to, from, next) => {
  if (!store.state.UserToken) {
    if (to.path !== '/login') {
      next('/login')
    } else {
      next()
    }
  } else {
    if (!store.state.auth.permissionList) {
      store.dispatch('auth/FETCH_PERMISSION').then(() => {
        next({ path: to.path })
      })
    } else {
      if (to.path !== '/login') {
        next()
      } else {
        next(from.fullPath)
      }
    }
  }
})

router.afterEach((to, from, next) => {
  var routerList = to.matched
  store.commit('SET_CRUMB', routerList)
  store.commit('auth/SET_CURRENT_MENU', to.name)
})